package com.qfedu.dtboot.controller;

import com.qfedu.dtboot.annotation.MyLog;
import com.qfedu.dtboot.entity.SysMenu;
import com.qfedu.dtboot.entity.SysUser;
import com.qfedu.dtboot.service.SysMenuService;
import com.qfedu.dtboot.service.SysUserService;
import com.qfedu.dtboot.util.DataGridResult;
import com.qfedu.dtboot.util.Query;
import com.qfedu.dtboot.util.R;
import com.qfedu.dtboot.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 菜单管理(SysMenu)表控制层
 *
 * @author ykx
 * @since 2022-09-27 13:02:35
 */
@RestController
@RequestMapping("sys/menu")
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysMenuService sysMenuService;

    @Autowired
    private SysUserService sysUserService;
    /**
     * 通过主键查询单条数据
     *
     * @return 单条数据
     */
    @GetMapping("/list")
    @MyLog("登录了系统")
    public DataGridResult getAll(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);//进一步处理参数
        return sysMenuService.getPageList(query);
    }

    @GetMapping("/user")
    public R getMenuList(){
        SysUser sysUser = ShiroUtils.getUserEntity();
        System.out.println("sysUser = " + sysUser);
        R r = new R();
        r.put("menuList",sysMenuService.queryMenuList(sysUser.getUserId()));
        r.put("permissions", sysUserService.getUserPermissions(sysUser.getUserId()));
        return r;
    }

}
